﻿using myBackupService.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace myBackupService
{
    public partial class frmSetting : Form
    {
        public frmSetting()
        {
            InitializeComponent();
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog(); 
            if(dialog.ShowDialog()==DialogResult.OK)
            {
                dataGridView_paths.Rows.Add(dialog.SelectedPath);
            }
        }

        private void button_delete_Click(object sender, EventArgs e)
        {
            var rows = dataGridView_paths.SelectedRows;
            foreach (DataGridViewRow row in rows)
            {
                dataGridView_paths.Rows.Remove(row);
            }
            
        }

        private void frmSetting_Load(object sender, EventArgs e)
        {
            textBox_port.Text = BackupConfig.Instance.Port.ToString();
            foreach (var item in BackupConfig.Instance.Paths)
            {
                dataGridView_paths.Rows.Add(item.Value.Path);
            }
        }

        private void button_save_Click(object sender, EventArgs e)
        {
            BackupConfig.Instance.Port = Convert.ToInt32(textBox_port.Text);
            BackupConfig.Instance.Paths.Clear();
            foreach (DataGridViewRow row in dataGridView_paths.Rows)
            {
                BackupConfig.Instance.AddPath(row.Cells[0].Value.ToString());
            }
            BackupConfig.Instance.Save();
        }
    }
}
